﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.IdentityModel.Tokens;
using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using System.Text;
using Abp.Runtime.Security;

namespace Ny.CenterServers.Account
{
    [AllowAnonymous]
    public class AccountAppservice : IAccountAppService
    {
        public string GetToken(string name, string psd)
        {
            if (name == "1" && psd == "1")
            {
                var claims = new Claim[] {
                    new Claim(AbpClaimTypes.UserId, "1"),
                    new Claim(AbpClaimTypes.UserName, "shaoshandong"),
                    new Claim(AbpClaimTypes.TenantId, "1"),
                    new Claim(AbpClaimTypes.Role, "admin,Manage"),
                 };
                var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("naiyejituan Corpright @2018"));
                var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
                var token = new JwtSecurityToken(
                    "ny",
                    "ny",
                    claims,
                    DateTime.Now,
                    DateTime.Now.AddMinutes(30),
                    creds);
                return new JwtSecurityTokenHandler().WriteToken(token);
            }
            else
            {
                return "";
            }
        }


    }
}
